//
//  CYNavigationController.m
//  DDSocial
//
//  Created by 阿帕 on 2018/7/2.
//  Copyright © 2018年 XY. All rights reserved.
//

#import "CYNavigationController.h"
#import "GQGesVCTransition.h"

@interface CYNavigationController ()

@end

@implementation CYNavigationController

#pragma mark - load初始化一次
+ (void)load
{
    [self setUpBase];
}

#pragma mark - LifeCyle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [GQGesVCTransition validateGesBackWithType:GQGesVCTransitionTypePanWithPercentRight withRequestFailToLoopScrollView:YES]; //手势返回
}

#pragma mark - 初始化
+ (void)setUpBase
{
    UINavigationBar *bar = [UINavigationBar appearance];
    bar.barTintColor = RGB(255, 255, 255);
    [bar setTintColor:RGB(255, 255, 255)];
    bar.translucent = NO;
//    [bar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
    // 设置导航栏字体颜色
    UIColor * naiColor = Dark_TextColor;
    attributes[NSForegroundColorAttributeName] = naiColor;
//    attributes[NSFontAttributeName] = PFR18Font;
    bar.titleTextAttributes = attributes;
    
}

#pragma mark - 返回
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    if (self.childViewControllers.count >= 1) {
        //返回按钮自定义
        UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        negativeSpacer.width = -15;
        
        UIButton *button = [[UIButton alloc] init];
        [button setImage:[UIImage imageNamed:@"gcy_img_nav_lArrow"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"gcy_img_nav_lArrow"] forState:UIControlStateHighlighted];
        button.frame = CGRectMake(0, 0, 17, 32);
        
        if (@available(ios 11.0,*)) {
//            button.contentEdgeInsets = UIEdgeInsetsMake(0, -15,0, 0);
//            button.imageEdgeInsets = UIEdgeInsetsMake(0, -10,0, 0);
        }
        
        [button addTarget:self action:@selector(backButtonTapClick) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:button];
        
        viewController.navigationItem.leftBarButtonItems = @[negativeSpacer, backButton];
        
        viewController.hidesBottomBarWhenPushed = YES;
        
        // 就有滑动返回功能
        self.interactivePopGestureRecognizer.delegate = nil;
    }
    //跳转
    [super pushViewController:viewController animated:animated];
}

#pragma mark - 点击返回
- (void)backButtonTapClick {
    
    if (self) {
        [self popViewControllerAnimated:YES];
    } else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}


@end
